using System;
using System.Collections;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;

namespace AreaBuilder {
    [XmlRoot(ElementName = "woot")]
    [Serializable]
    public class Mobile {
        private ArrayList mobFlags = new ArrayList();
        private ArrayList mobProgs = new ArrayList();

        [XmlAttribute(AttributeName = "vnum")]
        public int VNum { get; set; }

        [XmlElement(ElementName = "keywords")]
        public String Keywords { get; set; }

        [XmlElement(ElementName = "name")]
        public String Name { get; set; }

        [XmlElement(ElementName = "short")]
        public String Short { get; set; }

        [XmlElement(ElementName = "long")]
        public String Long { get; set; }

        [XmlElement(ElementName = "race")]
        public String Race { get; set; }

        [XmlElement(ElementName = "action")]
        public String Action { get; set; }

        [XmlElement(ElementName = "affects")]
        public String Affects { get; set; }

        [XmlElement(ElementName = "moreAffects")]
        public String MoreAffects { get; set; }

        [XmlElement(ElementName = "alignment")]
        public int Align { get; set; }

        [XmlElement(ElementName = "mobGroup")]
        public int MobGroup { get; set; }

        [XmlElement(ElementName = "level")]
        public int Level { get; set; }

        [XmlElement(ElementName = "class")]
        public int Class { get; set; }

        [XmlElement(ElementName = "castLevel")]
        public int CastLevel { get; set; }

        [XmlElement(ElementName = "hitDice")]
        public String HitDice { get; set; }

        [XmlElement(ElementName = "manaDice")]
        public String ManaDice { get; set; }

        [XmlElement(ElementName = "damBonus")]
        public int DamageBonus { get; set; }

        [XmlElement(ElementName = "damDice")]
        public String DamageDice { get; set; }

        [XmlElement(ElementName = "damType")]
        public String DamageType { get; set; }

        [XmlElement(ElementName = "pierce")]
        public int Pierce { get; set; }

        [XmlElement(ElementName = "bash")]
        public int Bash { get; set; }

        [XmlElement(ElementName = "slash")]
        public int Slash { get; set; }

        [XmlElement(ElementName = "magical")]
        public int Magical { get; set; }

        [XmlElement(ElementName = "offensiveFlags")]
        public String Offensive { get; set; }

        [XmlElement(ElementName = "immuneFlags")]
        public String Immune { get; set; }

        [XmlElement(ElementName = "resistFlags")]
        public String Resist { get; set; }

        [XmlElement(ElementName = "vulnFlags")]
        public String Vulnerable { get; set; }

        [XmlElement(ElementName = "startPos")]
        public String StartPos { get; set; }

        [XmlElement(ElementName = "defaultPos")]
        public String DefaultPos { get; set; }

        [XmlElement(ElementName = "sex")]
        public String Sex { get; set; }

        [XmlElement(ElementName = "treasure")]
        public int Treasure { get; set; }

        [XmlElement(ElementName = "formFlags")]
        public String Form { get; set; }

        [XmlElement(ElementName = "partFlags")]
        public String Part { get; set; }

        [XmlElement(ElementName = "size")]
        public int Size { get; set; }

        [XmlElement(ElementName = "clan")]
        public String Clan { get; set; }

        [XmlElement(ElementName = "materialType")]
        public String Material { get; set; }

        [XmlArray("mobProgs")]
        [XmlArrayItem("prog", typeof (MobProgLink))]
        public ArrayList Progs {
            get { return mobProgs; }
            set { mobProgs = value; }
        }

        [XmlArray("mobFlags")]
        [XmlArrayItem("flag", typeof (MobFlag))]
        public ArrayList Flags {
            get { return mobFlags; }
            set { mobFlags = value; }
        }

        public void AddProg(MobProgLink m) {
            mobProgs.Add(m);

            //Console.WriteLine("- Added mobprog link: {0}/{1}", m.Trigger, m.Program);
        }

        public void AddFlag(MobFlag m) {
            mobFlags.Add(m);

            //Console.WriteLine("- Added mobflag: {0}", m.FlagType);
        }

        public Mobile Clone() {
            var ms = new MemoryStream();
            var bf = new BinaryFormatter();

            bf.Serialize(ms, this);

            ms.Seek(0, SeekOrigin.Begin);

            var m = bf.Deserialize(ms) as Mobile;
            ms.Close();

            return m;
        }
    }
}